<template>
  <div class="container">
    <div class="title">
      检查结果<el-button
        type="primary"
        plain
        size="small"
        :disabled="!formatCheckResult.length && !contentCheckResult.length"
        @click="handleExport"
        >导出报告</el-button
      >
    </div>
    <div class="card-list">
      <div class="card">
        <div class="card-title">格式</div>
        <div class="item-list">
          <div class="item" v-for="(item, index) of formatCheckResult" :key="`fmt_` + index" @click="onClick(item)">
            {{ item.checkResult }}
          </div>
        </div>
      </div>

      <div class="card">
        <div class="card-title">内容</div>
        <div class="item-list">
          <div class="item" v-for="(item, index) of contentCheckResult" :key="`cnt_` + index" @click="onClick(item)">
            {{ item.checkResult }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import tinymce from 'tinymce'
import { scrollTo } from '@/utils/helpers'
import { checkExport, getCheckList } from '@/api'
export default {
  computed: {
    checkResult() {
      return this.$store.state.xmleditor.checkResult
    },
    formatCheckResult() {
      return this.checkResult?.formatCheckResult || []
    },
    contentCheckResult() {
      return this.checkResult?.contentCheckResult || []
    }
  },
  methods: {
    onClick(item) {
      const doc = tinymce.activeEditor.getDoc()
      const block = doc.querySelector(`[data-block-id="${item.contentId}"]`)
      const el = doc.querySelector(`[data-id="${item.contentId}"]`) || block
      scrollTo(tinymce.activeEditor.dom.getParent(el, '.page-sheet'), el)
    },
    handleExport: checkExport
  },
  mounted() {
    getCheckList()
  }
}
</script>

<style scoped>
.card {
  padding: 16px 0;
}
.card:not(:last-child) {
  border-bottom: 1px solid #999;
}
.card-title {
  border-left: 4px solid #025da4;
  padding-left: 6px;
  line-height: 1em;
  margin-bottom: 16px;
}
.card .item {
  font-size: 14px;
  color: #025da4;
  cursor: pointer;
  margin-bottom: 8px;
}
.card {
  counter-reset: section;
}
.card .item::before {
  counter-increment: section;
  content: counter(section) '. ';
}

/* 以下重复内容，可复用 */
.container {
  padding: 20px;
}

.title {
  font-size: 18px;
  font-weight: bold;
}
.input-row {
  margin: 10px 0;
}
::v-deep .el-input__inner {
  appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  height: 40px;
  line-height: 40px;
  outline: none;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
}
::v-deep .el-input-group__append {
  background-color: #f5f7fa;
  color: #909399;
  vertical-align: middle;
  display: table-cell;
  position: relative;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  padding: 0 20px;
  width: 1px;
  white-space: nowrap;
}
::v-deep .el-input-group__append {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;

  border-left: 0;
}
::v-deep .el-button {
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: #fff;
  border: 1px solid #dcdfe6;
  color: #606266;
  appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  transition: 0.1s;
  font-weight: 500;
  user-select: none;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
}
::v-deep .el-button--small {
  float: right;
  padding: 9px 15px;
  font-size: 12px;
  border-radius: 3px;
}
</style>
